package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;


public class SaveNewTablesSchedule {
	
	private  Vector<Vector<String>> vecTables;     // ordered by : x,y,size,number,type,name
	private int status=0;
	private PreparedStatement ps1;
	
	public SaveNewTablesSchedule(Vector<Vector<String>> vec)
	{
		this.vecTables=vec;

	}
	
	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}
	
	public void save()
	{
		SQLConnection sc=new SQLConnection();
		
		for(int i=0;i<vecTables.size();i++)
		{
		try {
		    ps1 = sc.getConnection().prepareStatement("INSERT INTO tableschedule(coordX,coordY,size,tId,orientation,scheduleName) values(?,?,?,?,?,?);");				
			ps1.setInt(1, Integer.parseInt(vecTables.get(i).get(0)));
			ps1.setInt(2, Integer.parseInt(vecTables.get(i).get(1)));
			ps1.setInt(3, Integer.parseInt(vecTables.get(i).get(2)));
			ps1.setInt(4, Integer.parseInt(vecTables.get(i).get(3)));
			ps1.setString(5, vecTables.get(i).get(4));
			ps1.setString(6, vecTables.get(i).get(5));			
			ps1.executeUpdate();
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		
		
		try {
			ps1.close();
			sc.getConnection().close();
			status=1;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
